using System;
using System.Collections.Generic;
using iPhOwa.Exchange.ContentClasses;
using iPhOwa.Exchange.ContentClasses.Fields;
using iPhOwa.Exchange.WebDav;
using iPhOwa.Exchange.WebDav.Methods;

namespace iPhOwa.Exchange.Managers
{
	/// <summary>
	/// Encapsulates working with notes.
	/// </summary>
	public static class NoteManager
	{
		/// <summary>
		/// Get a list of appointments.
		/// </summary>
		public static ICollection<Message> GetList(Uri path, OwaSession session)
		{
			var properties = new[]
			                 	{
			                 			ItemFields.Href
			                 			, MessageFields.Subject
			                 			, ItemFields.CreationDate
			                 	};

			var search = new Search(path, session, properties);
			search.OrderBys.Add(new OrderBy(ItemFields.CreationDate, SortDirection.Descending));

			var items = new List<Item>(search.Run());

			return items.ConvertAll(i => i as Message);
		}

		/// <summary>
		/// Get a specific appointment.
		/// </summary>
		public static Message Get(Uri path, OwaSession session)
		{
			var properties = new[]
			                 	{
			                 			ItemFields.Href
			                 			, MessageFields.Subject
			                 			, ItemFields.CreationDate
			                 			, MessageFields.TextDescription
			                 	};

			var propFind = new PropFind(path, session, properties);

			return (Message)propFind.Run();
		}
	}
}